import { useWsStore } from '@/stores/module/ws'
import storage from '@/storage'
export const wsLoginConnect = () => {
  let url = 'ws://10.102.233.52:8090'
  // let url = 'ws://10.104.0.106:15090'
  // let url = 'ws://47.115.216.167:15090'

  if (storage.get('token')) {
    url = `${url}?token=${storage.get('token')}`
  }
  const wsStore = useWsStore()
  const ws = new WebSocket(url)
  // const wsTimeout = 30000;
  ws.onopen = () => {
    console.log('WebSocket 连接已建立')
    // 心跳连接
    // setInterval(() => {
    //   ws.send(JSON.stringify({ type: 2 }));
    // }, wsTimeout);
  }
  wsStore.wsInstance = ws
}
